﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Documents;
using FirstFloor.ModernUI.Presentation;
using IsikFx.Project.ClientApp.Helpers;
using IsikFx.Project.CommonTypes;
using IsikFx.Project.CommonTypes.User;

namespace IsikFx.Project.ClientApp.Pages
{
    /// <summary>
    /// Interaction logic for FundEntry.xaml
    /// </summary>
    public partial class Actions : UserControl
    {
        public Actions()
        {
            InitializeComponent();
            HideControlsAccordingToUserRole();
        }
        private void HideControlsAccordingToUserRole()
        {
            User currentUser = Helper.CurrentUser;
            if (currentUser.RoleType == ((int)Helper.Roles.Sales))
            {
                RemoveLinkWithSourceName(new string[] { "FundIn", "FundOut" });
            }
            else if (currentUser.RoleType == ((int)Helper.Roles.Retention))
            {
                RemoveLinkWithSourceName(new string[] { "CustomerEntry" });
            }
        }

        private void RemoveLinkWithSourceName(string[] source)
        {
            List<Link> linkList = tabs.Links.ToList();
            if ((linkList.Count == 0) || (linkList == null) || (source.Length == 0) || source == null)
                return;
            for (int i = 0; i < source.Length; i++)
            {
                foreach (Link link in linkList)
                {
                    if (link.Source.ToString().Contains(source[i]))
                    {
                        tabs.Links.Remove(link);
                    }
                }
            }
            tabs.SelectedSource = tabs.Links.First().Source;
        }
    }
}
